'''
Created on 27/11/2012

@author: rcasal
'''

from geraldo import Report, landscape, ReportBand, ObjectValue
from reportlab.lib.pagesizes import LEGAL
from reportlab.lib.units import cm
from geraldo.base import DetailBand
from geraldo.utils import BAND_WIDTH
from geraldo.widgets import SystemField, Label
from reportlab.lib.enums import TA_RIGHT, TA_CENTER


class ReportConsultas(Report):
    '''
    classdocs
    '''
    title = 'Listado de Consultas'
    author = 'Si.Ge.Con'
    page_size = landscape(LEGAL)
    print_if_empty = True
    
    def __init__(self, queryset=None, title = ''):
        Report.__init__(self, queryset=queryset)
        self.title = title
    
    class band_detail(DetailBand):
        height = 1.5*cm
        elements = [
            ObjectValue(expression='id', left=0.5*cm),
            ObjectValue(expression='creado_en', left=2*cm, get_value=lambda instance: instance.creado_en.strftime('%d/%m/%Y')),
            ObjectValue(expression='comunicacion.modalidad.descripcion', left=4*cm),
            ObjectValue(expression='comunicacion.condicion.descripcion', left=6.5*cm),
            ObjectValue(expression='consulta.descripcion', left=9*cm),
            ObjectValue(expression='subconsulta.descripcion', left=14.5*cm),
            ObjectValue(expression='respuesta.descripcion', left=20*cm),
            ObjectValue(expression='comentarios', left=24*cm),
            ObjectValue(expression='usuario.username', left=31*cm),
        ]
        borders = {'bottom': True}

    class band_page_header(ReportBand):
        height = 1.8*cm
        elements = [
            SystemField(expression='%(report_title)s', top=0.2*cm, left=0, width=BAND_WIDTH,
                style={'fontName': 'Helvetica-Bold', 'fontSize': 14, 'alignment': TA_CENTER}),
            SystemField(expression=u'Page %(page_number)d of %(page_count)d', top=0.1*cm,
                width=BAND_WIDTH, style={'alignment': TA_RIGHT}),
            Label(text="N", top=1.2*cm, left=0.5*cm),
            Label(text="Fecha", top=1.2*cm, left=2*cm),
            Label(text="Modalidad", top=1.2*cm, left=4*cm),
            Label(text="Consultante", top=1.2*cm, left=6.5*cm),
            Label(text="Consulta", top=1.2*cm, left=9*cm),
            Label(text="Subconsulta", top=1.2*cm, left=14.5*cm),
            Label(text="Respuesta", top=1.2*cm, left=20*cm),
            Label(text="Comentarios", top=1.2*cm, left=24*cm),
            Label(text="Usuario", top=1.2*cm, left=31*cm)
        ]
        borders = {'all': True}
        
    class band_page_footer(ReportBand):
        height = 0.5*cm
        elements = [
            Label(text='Si.Ge.Con Reports', top=0.1*cm),
            SystemField(expression='Printed in %(now:%Y, %b %d)s at %(now:%H:%M)s', top=0.1*cm,
                width=BAND_WIDTH, style={'alignment': TA_RIGHT}),
            ]
        borders = {'top': True}
        

        
        